<!--
    顶部快捷地图导航
-->
<template>
    <div class="topnav-body">
        <ul class="breadcrumb">
            <li v-for="item in currentRouteChain">
                <span v-if="$index == 0" class="glyphicon glyphicon-home"></span>
                <a v-link="{ path : item.path }">{{item.name}}</a>
            </li>
        </ul>
    </div>
</template>

<script>
    var util = require('../util/StringUtil');
    module.exports = {
        data: function () {
            return {
                routeTable: [
                    '_index', {grade: 1, name: '系统主页', path: '/index', parent: ''},
                    '_Company_', {grade: 1, name: '公司管理', path: '/index/allCompany', parent: '_index'},
                    '_index_allCompany', {grade: 2, name: '公司列表', path: '', parent: '_Company_'},
                    '_index_addCompany', {grade: 2, name: '录入信息', path: '', parent: '_Company_'},
                    '_Aariety_', {grade: 1, name: '品种管理', path: '/index/allAariety', parent: '_index'},
                    '_index_allAariety', {grade: 2, name: '品种列表', path: '', parent: '_Aariety_'},
                    '_index_addAariety', {grade: 2, name: '录入品种', path: '', parent: '_Aariety_'},
                    '_Code_', {grade: 1, name: '二维码', path: '/index/codeHistory', parent: '_index'},
                    '_index_codeHistory', {grade: 2, name: '生成历史', path: '', parent: '_Code_'},
                    '_index_codeManage', {grade: 2, name: '查询管理', path: '', parent: '_Code_'},
                    '_profile_', {grade: 1, name: '管理员', path: '/index/profile', parent: '_index'},
                    '_index_profile', {grade: 2, name: '个人信息', path: '', parent: '_profile_'},
                    '_index_editProfile', {grade: 2, name: '编辑信息', path: '', parent: '_profile_'},
                    '_index_modifyProfile', {grade: 2, name: '列表管理', path: '', parent: '_profile_'}
                ],
                currentRouteChain: [{name: '系统主页', path: '/index'}]
            }
        },
        methods: {
            initTopRoute: function () {
                var _this = this;
                var RouteTable = _this.routeTable;
                var routeName = util.Replace(_this.$route.path, '/', '_');
                var Chain = [];
                _this.buildRouteChain(RouteTable, routeName, Chain);
                _this.currentRouteChain = Chain;
            },
            // 算法烂啊啊啊
            buildRouteChain: function (RouteTable, routeName, Chain) {
                if (routeName == '_index') {
                    Chain.push({name: RouteTable[1].name, path: RouteTable[1].path});
                    return;
                }
                for (var i = 0; i < RouteTable.length; i = i + 2) {
                    if (RouteTable[i] == routeName) {
                        if (RouteTable[i + 1].parent != '') {
                            this.buildRouteChain(RouteTable, RouteTable[i + 1].parent, Chain);
                            Chain.push({name: RouteTable[i + 1].name, path: RouteTable[i + 1].path});
                            return;
                        }
                        return;
                    }
                }
            }
        },
        created: function () {
            this.initTopRoute();
        }
    }
</script>

<style>
    .topnav-body {
        margin-top: 2px;
    }

    .topnav-body .breadcrumb {
        background-color: #FFFFFF;
        border: 1px #1e88e5 solid;
        margin-bottom: 3px;
    }
</style>